package es.uclm.itsue.dosd;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class BasicCanvasActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new myGraphicsView(this));
    }
    
    static public class myGraphicsView extends View {
    	public myGraphicsView(Context context) {
    		super(context);
    	}
    	
    	@Override
        protected void onDraw(Canvas canvas) {

    		Log.i("ITSUE", canvas.getWidth() + "\t" + canvas.getHeight());

    		
    		// Canvas.drawColor()
//    		canvas.drawColor(Color.RED);
    	
    		
    		// Canvas.drawLine()
//        	Paint paint = new Paint();
//        	paint.setColor(Color.YELLOW);
//        	paint.setStrokeWidth(10);
//        	canvas.drawLine(0, 0, 240, 400, paint);
    	
    		
    		// Canvas.drawLines()
//    		canvas.drawColor(Color.WHITE);
//    		
//        	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//        	paint.setColor(Color.RED);
//        	paint.setStrokeWidth(25);
//        	
//        	float[] pts = {
//        			100, 400, 400, 400,
//        			400, 400, 420, 100,
//        			420, 100, 100, 400 };
//        	canvas.drawLines(pts, paint);

    		
        	// Canvas.drawCircle() 
//        	Paint paint = new Paint();
//    		paint.setColor(Color.BLUE);
//        	canvas.drawCircle(100, 100, 50, paint);
//
//        	paint.setColor(Color.YELLOW);
//        	paint.setStrokeWidth(20);
//        	paint.setStyle(Paint.Style.STROKE);
//        	canvas.drawCircle(200, 200, 50, paint);
//        	
//        	
    		// Canvas.DrawRect()
//        	Paint paint = new Paint();
//        	paint.setColor(Color.GREEN);
//        	canvas.drawRect(200,300,300,500,paint);
//        	
//        	paint.setColor(Color.LTGRAY);
//        	paint.setStyle(Paint.Style.STROKE);
//        	paint.setStrokeWidth(10);
//        	canvas.drawRect(100,400,400,600,paint);
    		
    		
    		// Color
//    		Paint paint = new Paint();
//        	paint.setColor(Color.GREEN);
//        	canvas.drawRect(100,200,300,300,paint);
//        	
//        	paint.setColor(Color.argb(120, 255, 0, 255));
//        	canvas.drawRect(150,100,250,400,paint);   		
    		
    		
    		// LinearGradient
//    		
//    		LinearGradient linGrad = new LinearGradient(
//    				0, 0, 100, 50, 
//    				Color.RED, Color.LTGRAY, 
//    				Shader.TileMode.MIRROR);
//    		
//        	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//    		paint.setColor(Color.BLUE);
//    		paint.setShader(linGrad);
//        	canvas.drawCircle(100, 100, 200, paint);
//        	canvas.drawRect(200,200,400,400,paint);   		
    		
    		
    		// RadialGradient
    		
//    		RadialGradient radGrad = new RadialGradient(    				
//    				200, 250, 250, 
//    				new int[] { 
//    						Color.CYAN, 
//    						Color.BLUE, 
//    						Color.DKGRAY }, 
//    				new float[] { 
//    						(float) 0.0, 
//    						(float) 0.8, 
//    						(float) 1.0 },  
//    				Shader.TileMode.CLAMP );
//    		
//        	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//    		paint.setColor(Color.BLUE);
//    		paint.setShader(radGrad);
//        	canvas.drawCircle(240, 300, 200, paint);
    		
    		
        	// SweepGradient
    		
    		SweepGradient sweepGrad = new SweepGradient(    				
    				240, 300, 
    				new int[] { 
    						Color.RED, 
    						Color.YELLOW,
    						Color.GREEN,
    						Color.CYAN,
    						Color.BLUE,
    						Color.MAGENTA,
    						Color.RED}, 
    				null );
    		
        	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    		paint.setColor(Color.BLUE);
    		paint.setShader(sweepGrad);
        	canvas.drawCircle(240, 300, 200, paint);   
    		
    		
    		
    		
        	
    		// Canvas.drawText
//        	Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
//        	textPaint.setColor(Color.WHITE);
//        	textPaint.setTextSize(50);
//        	canvas.drawText("Esto es un texto", 100, 100, textPaint);
    		
        }
    	
    }
}
